package com.gali.juc;

/**
 * @Auther: gali
 * @Date: 2022-08-19 17:06
 * @Description:
 */
public class ReEntryLock {
    public synchronized void m1(){
        System.out.println(Thread.currentThread().getName()+"\t come in ");
        m2();
        System.out.println(Thread.currentThread().getName()+"\t end ");
    }
    public synchronized void m2(){
        System.out.println(Thread.currentThread().getName()+"\t come in ");
        m3();
        System.out.println(Thread.currentThread().getName()+"\t end ");
    }
    public synchronized void m3(){
        System.out.println(Thread.currentThread().getName()+"\t come in ");
        System.out.println(Thread.currentThread().getName()+"\t end ");
    }
    public static void main(String[] args) {
//        reEntryM1();
        ReEntryLock reEntryLock = new ReEntryLock();
        reEntryLock.m1();
    }

    private static void reEntryM1() {
        final Object object=new Object();
        new Thread(()->{
            synchronized (object){
                System.out.println("a：外层调用");
                synchronized (object){
                    System.out.println("a：中层调用");
                    synchronized (object){
                        System.out.println("a：内层调用");
                    }
                }
            }
        },"a").start();
    }
}
